package com.app.studyroom.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.app.studyroom.R;
import com.app.studyroom.api.model.ssrBooking.BookingItem;

import java.util.List;

public class BookingManageAdapter extends RecyclerView.Adapter<BookingManageAdapter.BookingViewHolder> {

    private List<BookingItem> bookingList;

    public BookingManageAdapter(List<BookingItem> bookingList) {
        this.bookingList = bookingList;
    }

    public void setBookingList(List<BookingItem> bookingList) {
        this.bookingList = bookingList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public BookingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_booking_manage, parent, false);
        return new BookingViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BookingViewHolder holder, int position) {
        BookingItem booking = bookingList.get(position);
        holder.tvRoomPlace.setText(booking.getRoomPlace());
        holder.tvSeatNum.setText(booking.getSeatNum());
        holder.tvTimeStart.setText(booking.getBookingStartTime());
        holder.tvTimeEnd.setText(booking.getBookingEndTime());
        holder.tvBookingUser.setText(String.valueOf(booking.getBookingUser()));//标记一下
        holder.tvNumberUser.setText(booking.getUserNumber());
        holder.tvQyAdmin.setText(booking.getQyAdmin());
    }

    @Override
    public int getItemCount() {
        return bookingList != null ? bookingList.size() : 0;
    }

    public static class BookingViewHolder extends RecyclerView.ViewHolder {
        TextView tvRoomPlace, tvSeatNum, tvTimeStart, tvTimeEnd, tvBookingUser, tvNumberUser, tvQyAdmin;

        public BookingViewHolder(@NonNull View itemView) {
            super(itemView);
            tvRoomPlace = itemView.findViewById(R.id.tv_room_place);
            tvSeatNum = itemView.findViewById(R.id.tv_seat_num);
            tvTimeStart = itemView.findViewById(R.id.tv_time_start);
            tvTimeEnd = itemView.findViewById(R.id.tv_time_end);
            tvBookingUser = itemView.findViewById(R.id.tv_booking_user);
            tvNumberUser = itemView.findViewById(R.id.tv_number_user);
            tvQyAdmin = itemView.findViewById(R.id.tv_qy_Admin);
        }
    }
}
